#include<bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define debug  freopen("in.txt","r",stdin),freopen("out.txt","w",stdout);
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 1e6+10;
const int mod = 1e9 + 7;
using namespace std;

ll N,K;
struct node
{
	ll M[55][55];
};
node xi,ans;

node mul(const node & A,const node & B){
	node ans;
	memset(ans.M,0,sizeof ans.M);
	for(int i = 1;i<=N;i++){
		for(int j = 1;j<=N;j++){
			for(int k = 1;k<=N;k++){
				ans.M[i][j] += A.M[i][k] * B.M[k][j]%mod; ans.M[i][j] %= mod;
			}
		}
	}
	return ans;
}

int main(){
	// debug;
	ios;

	cin>>N>>K;
	for(int i = 1;i<=N;i++) for(int j = 1;j<=N;j++) cin>>xi.M[j][i];
	for(int i = 1;i<=N;i++) ans.M[i][1] = 1;
	while(K){
		if(K & 1) ans = mul(xi,ans);
		xi = mul(xi,xi);
		K >>= 1;
	}
		
	ll res = 0;
	for(int i = 1;i<=N;i++) res = (res + ans.M[i][1]) %mod;
	cout<<res<<'\n';
	
	return 0;
}
